<template>
    <div>
        <div style="position: absolute;height: 100%;left: 0;top: 0;right: 0;background-color: #444444;z-index: -1;">
        </div>
        <div style="height: 50%;width: 100%;">
            <image src="http://ydsports.test.upcdn.net/auto.jpg" mode="aspectFill" class="img">
            </image>
            <div style="position: absolute;top: 20%;width: 100%;">
                <div style="text-align: center;padding: 30rpx;">
                    <span
                        style="color: aliceblue;font-size: 60rpx;font-weight: bold;margin: 30rpx 0;display: block;font-style: italic;">SALOMON</span>
                </div>
            </div>
            <div style="position: absolute;top: 50%;width: 100%;">
                <div style="text-align: center;padding: 30rpx;">
                    <span
                        style="color: aliceblue;font-size: 40rpx;font-weight: bold;margin: 30rpx 0;display: block;">越野社区</span><br>
                    <span style="color: aliceblue;font-size: 30rpx;">这里有过更多户外爱好者同你一起越野，不为比赛，只为尽兴</span>
                </div>
                <button @click="login" type="primary" open-type="getUserProfile">加入SALOMON</button>
            </div>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            code: '',
            userInfo: '',
            iv: "",
            signature: '',
            encryptedData: ''
        }
    },
    onLoad() {
    },
    methods: {
        login() {
            uni.getUserProfile({
                lang: 'zh_CN',
                desc: '用户登录', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，
                success: (res) => {
                    let _userProFile = res
                    uni.login({
                        success: (res) => {
                            console.log('用户登录凭证', res.code);
                            console.log(_userProFile.userInfo,'userInfo');
                            let requestParam = {
                                code: res.code,
                                userInfo: JSON.stringify(_userProFile.userInfo),
                                encryptedData: _userProFile.encryptedData,
                                signature: _userProFile.signature,
                                iv: _userProFile.iv,
                            }
                            this.request({
                                url: '/api/wxlogin',
                                method: 'post',
                                data: requestParam
                            }).then(res => {
                                console.log('登录成功', res);
                                if (res.data.status === 200) {
                                    uni.setStorageSync('ugo-token-150', res.data.token)
                                    uni.navigateBack()
                                } else {
                                    uni.showToast({
                                        title: '登录失败！'
                                    })
                                }
                            })
                        },
                        fail: (fail) => {
                            console.log('登录错误提示', fail);
                        },
                    });
                },
                fail: (err) => {
                    console.log(err);
                }
            })


        },

    }
}
</script>

<style>
button {
    width: 600rpx;
    margin: 200rpx auto 0;
}

.img {
    width: 100%;
    height: 1000rpx;
    mask: linear-gradient(360deg, transparent, #fff);
}
</style>
